package cn.kgc.ssm.service.impl;

import cn.kgc.ssm.dto.LogInfoPageDTO;
import cn.kgc.ssm.entity.LogInfo;
import cn.kgc.ssm.mapper.LogInfoMapper;
import cn.kgc.ssm.response.ResponseResult;
import cn.kgc.ssm.service.LogInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/11/22
 * @description
 */
@Service
public class LogInfoServiceImpl implements LogInfoService {

    @Autowired
    private LogInfoMapper logInfoMapper;


    @Override
    public ResponseResult logInfoPage(LogInfoPageDTO logInfoPageDTO) {


        PageHelper.startPage(logInfoPageDTO.getPage(),logInfoPageDTO.getLimit());
        List<LogInfo> tableData =  logInfoMapper.selectLogInfos(logInfoPageDTO.getDescription(),logInfoPageDTO.getModel());
        long total = new PageInfo<LogInfo>(tableData).getTotal();

        return ResponseResult.success().data(tableData).count(total);
    }

    @Transactional
    @Override
    public ResponseResult deleteLogInfo(List<Integer> ids) {

        logInfoMapper.deleteLogInfo(ids);

        return ResponseResult.success();
    }
}
